/* 1640. 能否连接形成数组 */
/**
 * @param {number[]} arr
 * @param {number[][]} pieces
 * @return {boolean}
 */
var canFormArray = function (arr, pieces) {
	const n = arr.length,
		m = pieces.length
	const index = new Map()
	for (let i = 0; i < m; i++) {
		index.set(pieces[i][0], i)
	}
	for (let i = 0; i < n; ) {
		if (!index.has(arr[i])) return false
		const j = index.get(arr[i]),
			len = pieces[j].length
		for (let k = 0; k < len; k++) {
			if (arr[i + k] !== pieces[j][k]) return false
		}
		i += len
	}
	return true
}
canFormArray([91, 4, 64, 78], [[78], [4, 64], [91]])
